package com.barbarossa.activity;

import java.io.File;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

import com.ipaulpro.afilechooser.FileChooserActivity;
import com.ipaulpro.afilechooser.utils.FileUtils;

public class TorrentFileChooserActivity extends FileChooserActivity {
	private static final String TAG = "TorrentFileChooserActivity";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Uri uri = getIntent().getData();
		if (null != uri) {
			Intent intent = new Intent(this, VodassistActivity.class);
			intent.setData(getIntent().getData());
			intent.setAction(VodassistActivity.ACTION_OPENFILE);
			startActivity(intent);
			finish();
		}
	}

	@Override
	protected void onFileSelect(File file) {
		if (file != null) {
			final Context context = getApplicationContext();
			
			// Get the path of the Selected File.
			final String path = file.getAbsolutePath();
			Log.d(TAG, "File path: " + path);

			// Get the MIME type of the Selected File.			
			String mimeType = FileUtils.getMimeType(context, file);
			Log.d(TAG, "File MIME type: " + mimeType);

			// Get the thumbnail of the Selected File, if image/video
//			final Uri uri = Uri.fromFile(file);
//			Bitmap bm = FileUtils.getThumbnail(context, uri, mimeType);

			finish();
		}	
	}

	@Override
	protected void onFileError(Exception e) {
		Log.e(TAG, "File select error", e);
		finish();
	}

	@Override
	protected void onFileSelectCancel() {
		Log.d(TAG, "File selections canceled");
		finish();
	}

	@Override
	protected void onFileDisconnect() {
		Log.d(TAG, "External storage disconneted");
		finish();
	}
}
